<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <button @click="fn1">改名</button>
        <input type="text" v-model="firstName"> + <input type="text" v-model="lastName"> = {{ fullName }}
    </div>

    <script src="./vue.js"></script>
    <script>
        new Vue({
            el: '#app',
            data() {
                return {
                    firstName: '',
                    lastName: ''
                }
            },

            methods: {
                fn1() {
                    this.fullName = '蔡徐乾'
                }
            },

            computed: {
                // // 这种写法的计算属性是简写形式，只能读取，不能修改
                // fullName() {

                //     return this.firstName + this.lastName
                // },

                // 完整写法：计算属性既可以读取，也可以修改
                fullName: {
                   
                    // 对计算属性赋值的方法（修改他）
                    set (val) {
                        console.log('我赋值了', val)
                        this.firstName = val[0]
                        this.lastName = val.substring(1)
                    },

                    // 对计算属性取值的方法
                    get () {
                        return this.firstName + this.lastName
                    },
                }
            }
        })
    </script>
</body>

</html>